package edu.chen.aspect;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.hibernate.mapping.Join;
import org.springframework.stereotype.Component;

@Aspect      //Aop注解
@Component   //组件注解
public class testAspect{

    /**
     * 定义切点
     */
    @Pointcut("execution(* edu.chen.service.*.*(..))")
    public void servicePointcut(){}

    /**
     * 在方法执行前调用
     */
    @Before("servicePointcut()")
    public void before(){
        System.out.println("before this method running");
    }

    /**
     * 在方法返回返回值的时候调用
     */
//    @AfterReturning("servicePointcut()")
//    public void afterReturning(){
//        System.out.println("after this method return a parameter");
//    }

    /**
     * 在方法执行之后调用
     */
    @After("servicePointcut()")
    public void after(){
        System.out.println("after this method is finished");
    }

    /**
     * 环绕切点,ProceedingJoinPoint可以用来控制程序的运行
     * @param proceedingJoinPoint
     * @throws Throwable
     */
    @Around("servicePointcut()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("around the method : before");
        Object object = proceedingJoinPoint.proceed();
        System.out.println("around the method : after");
        return object;
    }


    /**
     * 抛出异常时调用
     */
//    @AfterThrowing("servicePointcut()")
//    public void afterThrowing(){
//        System.out.println("after this method throwing a throwable");
//    }
}
